package com.raos.example.redis.networkmodel.multireactor;

import java.io.IOException;
import java.util.concurrent.Executor;
import java.util.concurrent.Executors;

/**
 * 多线程Reactor 模型（高性能I/O设计模式）
 * 模拟优化实例写法
 *
 * @author raos
 * @emil 991207823@qq.com
 * @date 2021/7/24 22:04
 **/
public class MultiplyReactor {

    private int port;

    //main Reactor
    private Reactor mainReactor;

    private Executor mainReactorExecutor = Executors.newFixedThreadPool(10);

    public MultiplyReactor(int port) throws IOException {
        this.port = port;
        mainReactor = new Reactor();
    }

    public void start() throws IOException {
        new Acceptor(mainReactor.getSelector(), port);
        mainReactorExecutor.execute(mainReactor);
    }

    public static void main(String[] args) throws IOException {
        new MultiplyReactor(8080).start();
    }

}
